package com.central.scheduler.spi.classloader;

import java.io.Closeable;

/**
 * @author Tindy
 * @date 2021/10/26
 * @describe
 */
public class ThreadContextClassLoader
        implements Closeable {
    private final ClassLoader threadContextClassLoader;

    public ThreadContextClassLoader(ClassLoader newThreadContextClassLoader) {
        this.threadContextClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(newThreadContextClassLoader);
    }

    @Override
    public void close() {
        Thread.currentThread().setContextClassLoader(threadContextClassLoader);
    }
}